package Java_Concurrency_in_Practice.c3_4_2;

import java.math.BigInteger;

/**
 * 使用指向不可变容器对象的volatile类型引用以缓存最新的结果
 * @author xiangke
 *
 */
public class VolatileCachedFactorizer {
	
	private volatile OneValueCache cache = new OneValueCache(null, null);
	
	public BigInteger[] service(BigInteger i) {
		BigInteger[] factors = cache.getFactors(i);
		if (factors == null) {
			factors = factor(i);
			cache = new OneValueCache(i, factors);
		}
		return factors;
	}

	private BigInteger[] factor(BigInteger i) {
		return null;
	}

}
